package action_行为型.iterator_pattern_迭代器模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/08/15:00
 * @Description:
 */
public class NamesRepository implements Container<String> {

	private final String[] names = { "zhangsan", "lisi", "wangwu", "fengliu" };

	@Override public MYIterator<String> getIterator() {
		return new NamesRepositoryIterator();
	}

	private class NamesRepositoryIterator implements MYIterator<String> {

		int index = 0;

		@Override public boolean hasNext() {
			return index < names.length;
		}

		@Override public String next() {
			return hasNext() ? names[index++] : null;
		}
	}
}
